import 'package:flutter/material.dart';
import 'package:gif/gif.dart';
import '../../manger/user_manger.dart';

// 修改类定义，使其实现 PreferredSizeWidget 接口
class CommonTopView extends StatelessWidget implements PreferredSizeWidget {
  final VoidCallback onPop;
  final VoidCallback onPushContact;
  final Function(bool) onShowUnfold;
  final bool isUnfold;

  CommonTopView({
    Key? key,
    required this.onPop,
    required this.onPushContact,
    required this.onShowUnfold,
    required this.isUnfold,
  }) : super(key: key);

  // 实现 PreferredSizeWidget 接口的 preferredSize 属性
  @override
  Size get preferredSize => const Size.fromHeight(50); // 根据实际情况调整高度

  @override
  Widget build(BuildContext context) {
    final statusBarHeight = MediaQuery.of(context).padding.top;
    return Container(
      padding: EdgeInsets.only(left: 0, right: 0, top: 0, bottom: 1),
      height: 40 + statusBarHeight,
      color: Colors.white,
      child: Stack(
        children: [
          Positioned(
            left: 10,
            bottom: -5,
            child: IconButton(
              icon: Image.asset('assets/images/leftpush.png', height: 22, width: 22),
              onPressed: onPop,
            ),
          ),
          // 修改这部分，使用 Positioned 定位 verIcon.png
          Positioned(
            bottom: 4,
            left: 0,
            right: 0,
            child: Center(
              child: Image.asset('assets/images/verIcon.png', width: 120, height: 36),
            ),
          ),
          Positioned(
            right: 12,
            bottom: 2,
            child: GestureDetector(
              onTap: onPushContact,
              child: Gif(
                image: AssetImage('assets/images/kefu_logo2.gif'),
                width: 40,
                height: 40,
                fps: 10,
                autostart: Autostart.loop,
              ),
            ),
          ),
          Positioned(
            right: 58,
            bottom: 5,
            child: SizedBox(
              height: 30, 
              child: TextButton(
                onPressed: () {
                  onShowUnfold(!isUnfold);
                },
                style: TextButton.styleFrom(
                  backgroundColor: Colors.white,
                  shape: RoundedRectangleBorder(
                    // 新增边框样式，宽度为1，颜色为#E9E9E9
                    side: BorderSide(width: 1, color: Color(0xFFE9E9E9)), 
                    borderRadius: BorderRadius.circular(20),
                  ),
                  padding: EdgeInsets.symmetric(horizontal: 5),
                  // 移除 fixedSize，因为已经使用 SizedBox 设置高度
                ),
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text(UserInfos.shared.currencyListModel?.code ?? "USD", style: TextStyle(color: Color(0xFF000000), fontSize: 12)),
                    SizedBox(width: 2),
                    Image.asset(isUnfold ? 'assets/images/收起.png' : 'assets/images/展开1.png', width: 14, height: 14),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}